
from DailyBase import *
from AGDefines import *
import logging
from Log2File import *

logger = logging.getLogger(__name__)


class SuanGua(DailyBase):

    def __init__(self, enum):
        self.RCName = __name__
        self.LogHeader = self.RCName +str(enum.port)
        self.enum = enum
        self.started = False
        self.loadPrivateActions(self.areaDict, SuanGuaActions)
        logger.info("{} has {} actions".format(self.LogHeader, len(self.areaDict)))

    def KaiShi(self):
        Log2File.info(self.enum.port, "id {} 开始!!!".format(self.RCName))
        self.begin()

    def process_private(self, img = None, data = None):

        if self.areaDict['WoYaoSuanGua'].detect(img, self.enum) < 10:
            Log2File.info(self.enum.port, "id {} 我要算卦!!!".format(self.RCName))
            self.enum.click(self.areaDict['WoYaoSuanGua'].click)
        elif self.areaDict['SuanGua'].detect(img, self.enum) < 10:
            Log2File.info(self.enum.port, "id {} 算卦!!!".format(self.RCName))
            self.enum.click(self.areaDict['SuanGua'].click, 1000)
        elif self.areaDict['JieShou'].detect(img, self.enum) < 10:
            Log2File.info(self.enum.port, "id {} 接受卦象!!!".format(self.RCName))
            self.enum.click(self.areaDict['JieShou'].click)
            self.stop()
        elif self.areaDict['SuanGuoLe'].detect(img, self.enum) < 10:
            Log2File.info(self.enum.port, "id {} 算过了!!!".format(self.RCName))
            self.enum.click(self.areaDict['SuanGuoLe'].click)
            self.stop()
